package com.jame.basics.arithmetic;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

/**
 * @author : Jame
 * @date : 2021-05-23 13:50
 **/
public class Arithmetic {
    /**
     * 分组排序
     * 练习题
     */
    @Test
    public void test19() {
        ArrayList<String> list = new ArrayList<>();
        list.add("aaa003");
        list.add("aaa004");
        list.add("aaa003");
        list.add("bbb008");
        list.add("bbb002");
        list.add("bbb003");
        HashMap<String, ArrayList<Integer>> map = new HashMap<>();

        for (String s : list) {
            String keyword = s.substring(0, 3);
            if (map.get(keyword) == null) {
                ArrayList<Integer> arrayList = new ArrayList<Integer>();
                arrayList.add(Integer.parseInt(s.substring(3)));
                map.put(keyword, arrayList);
            } else {
                ArrayList<Integer> arrayList = map.get(keyword);
                arrayList.add(Integer.parseInt(s.substring(3)));
            }
        }

        Set<String> strings = map.keySet();
        for (String s : strings) {
            int max = 0;
            ArrayList<Integer> arrayList = map.get(s);
            for (Integer i : arrayList) {
                if (i > max) {
                    max = i;
                }
            }
            System.out.println(s+"最大值"+max);

        }
    }

}
